import { get, request, post } from '@/utils/request'

// export function test () {
//   return Promise.resolve({
//     code: 200,
//     data: [

//     ]
//   })
// }

function changeProtocol(url) {
  var res = url
  if (url.indexOf('http:') !== -1) {
    if (global.location.protocol === 'https:') {
      res = url.replace('http:', 'https:')
    }
  } else {
    res = global.location.protocol + '//' + url
  }
  return res
}

class EpCms {
  constructor(url, authKey) {
    this.url = changeProtocol(url)
    this.authKey = authKey || 'easipass'
  }

  /***
   * 获取栏目列表
   */
  columnList(column, page) {
    let { url, authKey } = this
    return get({
      url: `${url}/column/${column}/getJournalList`,
      headers: { key: authKey },
      params: page
    })
  }

  /***
   * 获取文章详情
   */
  journal(journalId) {
    let { url, authKey } = this
    return get({
      url: `${url}/journal/${journalId}`,
      headers: { key: authKey }
    })
  }
}
export function getHunterAuth(token) {
  return request({
    method: 'GET',
    url: `${global.HUNTERHOST}/epmaHunterAuth`,
    dataType: 'form',
    headers: {
    }
  })
}

export function test() {
  return Promise.resolve({
    code: 200,
    data: []
  })
}

export function saveHomeSec(data) {
  return post(
    {
      url: global.USERMANAGE + '/v1/user-profile/add',
      dataType: 'json'
    },
    data
  )
}

export function delEntryById(id) {
  return get({
    url: global.USERMANAGE + '/v1/user-profile/delete/' + `${id}`,
    dataType: 'json'
  })
}
export function getPartByType(id) {
  return get({
    url: global.USERMANAGE + '/v1/auth/my-view?view_type=' + `${id}`,
    dataType: 'json'
  })
}
export function getCardList(data) {
  return get({
    url: global.USERMANAGE + '/v1/auth/my-view?view_type=' + data.type,
    dataType: 'json'
  })
}
export function getCardListByPro(data) {
  return get({
    url: global.USERMANAGE + '/v1/auth/my-view?view_type=' + data.type + '&product_code=' + data.code,
    dataType: 'json'
  })
}

// 我发起的流程
export function myWorkFlowAll(data) {
  return get({
    url: global.WORKFLOW + '/statistics/count-started-process-by-myself?startTime=' + data.startTime + '&endTime=' + data.endTime,
    dataType: 'json'
  })
}
export function myWorkFlowDone(data) {
  return get({
    url:
      global.WORKFLOW +
      '/statistics/count-started-process-by-myself?status=' +
      data.status +
      '&startTime=' +
      data.startTime +
      '&endTime=' +
      data.endTime,
    dataType: 'json'
  })
}

// 组内任务
export function groupCountAll(data) {
  return get({
    url: global.WORKFLOW + '/statistics/count-candidate-my-group-process?startTime=' + data.startTime + '&endTime=' + data.endTime,
    dataType: 'json'
  })
}
export function groupCountDone(data) {
  return get({
    url: global.WORKFLOW + '/statistics/count-candidate-my-group-process-finished?startTime=' + data.startTime + '&endTime=' + data.endTime,
    dataType: 'json'
  })
}

//流转到我的任务
export function toMeAll(data) {
  return get({
    url: global.WORKFLOW + '/statistics/count-assign-to-me-process?startTime=' + data.startTime + '&endTime=' + data.endTime,
    dataType: 'json'
  })
}

export function toMeDone(data) {
  return get({
    url: global.WORKFLOW + '/statistics/count-assign-to-me-process-finished?startTime=' + data.startTime + '&endTime=' + data.endTime,
    dataType: 'json'
  })
}

// 活跃用户
export function activeUsers(data) {
  return get({
    url: global.SEARCHMANAGE + '/v1/view-component/number-of-active-users?seconds=' + data,
    dataType: 'json'
  })
}

// 首页消息列表
export function getMessageList(data) {
  return post(
    {
      url: global.USERMANAGE + '/v1/event-message/fm/search',
      dataType: 'json'
    },
    data
  )
}

// 标位已读
export function readMessage(data) {
  return get({
    url: global.USERMANAGE + '/v1/event-message/read?id=' + data,
    dataType: 'json'
  })
}

// 监控告警
export function alarmInfo(data) {
  return get({
    url: global.JKPROXY + '/v1/monitor/info',
    dataType: 'json'
  })
}
// 友情链接  删除
export function linkDel(id) {
  return get({
    url: global.USERMANAGE + '/v1/link/delete/' + id,
    dataType: 'json'
  })
}

//api性能指标
export function getQpsData(data) {
  return get({
    url:
      global.SEARCHMANAGE +
      '/v1/view-component/api-metric/qps?appname=' +
      data.appName +
      '&startTimestamp=' +
      data.startTimestamp +
      '&endTimestamp=' +
      data.endTimestamp,
    dataType: 'json'
  })
}
//错误数
export function getErrorNum(data) {
  return get({
    url:
      global.SEARCHMANAGE +
      '/v1/view-component/api-metric/errorNum?appname=' +
      data.appName +
      '&startTimestamp=' +
      data.startTimestamp +
      '&endTimestamp=' +
      data.endTimestamp,
    dataType: 'json'
  })
}
// 请求耗时
export function getReqTime(data) {
  return get({
    url:
      global.SEARCHMANAGE +
      '/v1/view-component/api-metric/reqTime?appname=' +
      data.appName +
      '&startTimestamp=' +
      data.startTimestamp +
      '&endTimestamp=' +
      data.endTimestamp,
    dataType: 'json'
  })
}

//资源表
export function getResource(data) {
  return get({
    url: global.VMHOST + '/v1/view-table/resource?projectCode=' + data.name,
    dataType: 'json'
  })
}

//猎户监控
export function getHunterMonitor(data) {
  return get({
    url: global.HUNTERHOST + '/monitor/home',
    dataType: 'form',
    params: data
  })
}

export function getHunterSchema(schema) {
  return get({
    url: global.HUNTERHOST + '/monitor/schema/' + schema
  })
}
export default EpCms
